#ifndef PCHUIAPP_H
#define PCHUIAPP_H

#include "syncdlg.h"
#include "pkglist.h"
#include "npipe.h"

class ListView;
class ZipFile;
class PathName;

class PatchUI : public SyncDialog, public NamedPipe
{
	public:
		PatchUI(HWND, HINSTANCE);
		~PatchUI();

		int	Run(void);

		void ioerror();
		void recvd(uint8* Msg, int32 Len);

	protected:
		void SetCurrentDirectory();
		void Init();
		void BrandTitle();
		void Add();
		void Remove();
		void Update();

		bool8 doAddPkg(PackageDescription*);
		bool8 doUpdatePkg(int32, PackageDescription*, PackageDescription*);

		int32 addLV(PackageDescription*);
		void updateLV(int32, PackageDescription*);
		BOOL DrawItem(const DRAWITEMSTRUCT*);
		void MeasureItem(MEASUREITEMSTRUCT*);
		int32 Notify(int, LPNMHDR);
		bool8 unzipPackage(PackageDescription *pkg);
		bool8 doUnzipPackage(ZipFile &zf, PathName &Dest);

		void netConnect();
		void netLogin();
		void netReqList(bool8);
		void netAddPkg(PackageDescription*);
		void netRemovePkg(int32);
		void netUpdatePkg(int32, PackageDescription*);

		void serverError(TCHAR*, int32);
		void fail(TCHAR*, bool8 isFatal = true);

		void loginRecvd(uint8*, int32);
		void listRecvd(uint8*, int32);
		void addPkgRecvd(uint8*, int32);
		void removePkgRecvd(uint8*, int32);
		void updatePkgRecvd(uint8*, int32);

		void dropFiles(WPARAM);
		void continueDrop();
		void addDropFile(TCHAR*);

		BOOL dialogProc(HWND, UINT, WPARAM, LPARAM);

	protected:
		PackageList	cPkgs;
		ListView*	cList;
		int32		cState;
		int32		cServerErr;

		int32		cCountToRecv, cWorkingIndex;

		int32				cPendingIndex;
		PackageDescription*	cPendingPkg;

		HANDLE		chDrop;
		int32		cDropCurrent, cDropTotal;
};

#endif
